package com.stedu.controller;

import com.stedu.bean.Admin;
import com.stedu.bean.RespBean;
import com.stedu.service.AdminService;
import com.stedu.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@CrossOrigin
@RestController
@RequestMapping("/admin/info")
public class InfoController extends HttpServlet {
    @Autowired
    private AdminService adminService;
    @GetMapping("/adminInfo")
    public  RespBean longinfo(HttpServletRequest request){
        //获取jwt
        String token = request.getHeader("token");

        Map<String,Object>map = JwtUtils.parseJwtToMap(token);
       Integer id = (Integer)map.get("id");



        Admin admin = adminService.selectById(id);
        //返回
       return RespBean.ok("",admin);
    }


    @GetMapping("/top5")
public RespBean top5DnameAndCount(){
    List<Map<String,Object>> mapList= adminService.selectTop5DnameAndCount();
    return RespBean.ok("", mapList);

}
    @GetMapping("/top6")
    public RespBean top6DnameAndCount(){
        Integer num =adminService.selectuserNumber();
            return RespBean.ok("",num);
}
}
